package com.yanchangapp.adapter._n_manage;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yanchangapp.R;
import com.yanchangapp.commom._PlanStatus;
import com.yanchangapp.model.bean.DailyPlanBean;
import com.zxl.baselib.util.ui.ResHelper;
import com.zzhoujay.markdown.parser.Line;

import java.util.List;

/**
 * Created by apple on 2019-10-10.
 * description:adapter...
 */
public class DailyPlanListAdapter extends BaseQuickAdapter<DailyPlanBean, BaseViewHolder> {
    private boolean isToday = false;

    public void setToday(boolean today) {
        isToday = today;
    }

    public DailyPlanListAdapter(@Nullable List<DailyPlanBean> data) {
        super(R.layout.item_daily_plan_list, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, DailyPlanBean item) {
        helper.setText(R.id.tvPlanItem,item.getTitle());
        helper.setText(R.id.tvState,item.getScheduleStatusName());

        LinearLayout llDeadTime =  helper.getView(R.id.llDeadTime);
        LinearLayout llFinishTime =  helper.getView(R.id.llFinishTime);
        if (isToday){
            llDeadTime.setVisibility(View.VISIBLE);
            String deadTime = null;
            if (item.getPredictTime() == null){
                deadTime = "今天";
            }else {
                if (item.getPredictTime() == 1){
                    deadTime = "今天";
                }else {
                    deadTime = item.getPredictTime() +"天";
                }
            }
            helper.setText(R.id.tvDeadTime,deadTime);
            llFinishTime.setVisibility(View.GONE);
        }else {
            llDeadTime.setVisibility(View.GONE);
            llFinishTime.setVisibility(View.VISIBLE);
            String endTime = item.getEndTime();
            if (endTime != null){
                helper.setText(R.id.tvFinishTime,endTime.substring(0,10));
            }
        }


        TextView tvAction =  helper.getView(R.id.tvAction);
        TextView tvState = helper.getView(R.id.tvState);
        ImageView ivState =  helper.getView(R.id.ivState);
        if (item.getScheduleStatus() == _PlanStatus.NOT_START.getStatus()){
            // 未开始
            helper.setText(R.id.tvAction,"开始工作");
            tvAction.setVisibility(View.VISIBLE);
            tvAction.setTextColor(ResHelper.getColor(R.color.colorPrimary));
            tvAction.setBackground(ResHelper.getDrawable(R.drawable.bg_item_plan_list));
            tvState.setTextColor(ResHelper.getColor(R.color.fontColorLight));
            ivState.setImageResource(R.mipmap.state_normal);
        }else if (item.getScheduleStatus() == _PlanStatus.LOADING.getStatus()){
            helper.setText(R.id.tvAction,"继续工作");
            tvAction.setTextColor(ResHelper.getColor(R.color.colorOrange));
            tvAction.setBackground(ResHelper.getDrawable(R.drawable.bg_item_plan_list_loading));
            tvAction.setVisibility(View.VISIBLE);
            ivState.setImageResource(R.mipmap.state_loading);
            tvState.setTextColor(ResHelper.getColor(R.color.colorOrange));
        }else if (item.getScheduleStatus() == _PlanStatus.CAN_FINISH.getStatus()){
            tvAction.setVisibility(View.GONE);
            ivState.setImageResource(R.mipmap.state_success);
            tvState.setTextColor(ResHelper.getColor(R.color.colorGreen));
        }else {
            ivState.setImageResource(R.mipmap.state_cannot);
            tvAction.setVisibility(View.GONE);
            tvState.setTextColor(ResHelper.getColor(R.color.colorRed));
        }
        helper.addOnClickListener(R.id.tvAction);
    }
}
